﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class TankAttack : MonoBehaviour
{
    public Transform firePosition;              //炮口
    public GameObject shellPrefab;              //子弹
    public KeyCode fireKey;                     //开火键
    public AudioClip fireAudio;                 //开火音效
    public float shellSpeed = 20.0f;            //子弹速度

    // Start is called before the first frame update
    void Start()
    {
        firePosition = transform.Find("FirePosition");
    }

    // Update is called once per frame
    void Update()
    {
        if(Input.GetKeyDown(fireKey)){
            AudioSource.PlayClipAtPoint(fireAudio, transform.position);
            GameObject go = GameObject.Instantiate(shellPrefab, firePosition.position, firePosition.rotation) as GameObject;
            go.GetComponent<Rigidbody>().velocity = go.transform.forward * shellSpeed;
        }
    }
}
